package com.woniuxy.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.platform.dto.ApprovalUser;
import com.woniuxy.platform.entity.Approval;
import com.woniuxy.platform.entity.User;
import com.woniuxy.platform.mapper.ApprovalMapper;
import com.woniuxy.platform.mapper.UserMapper;
import com.woniuxy.platform.service.ApprovalService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 流程审批表 服务实现类
 * </p>
 *
 * @author 杨青云
 * @since 2020-09-27
 */
@Service
public class ApprovalServiceImpl extends ServiceImpl<ApprovalMapper, Approval> implements ApprovalService {
    @Resource
    ApprovalMapper approvalMapper;

    @Resource
    UserMapper userMapper;

    @Override
    public List<ApprovalUser> showApproval(Page page) {
        List<ApprovalUser> approvalUsers=new  ArrayList<>();
        QueryWrapper<Approval> wrapper=new QueryWrapper<>();
        wrapper.eq("APPROVAL_STATE",0);
        List<Approval> approvals = approvalMapper.selectPage(page,wrapper).getRecords();
        for (Approval approval:approvals){
            ApprovalUser approvalUser=new ApprovalUser();
            //添加为封装的实体类
            approvalUser.setApproval(approval);
            approvalUser.setApprovalUser(selectById(approval.getApprovalUserId()));
            approvalUser.setLaunchUser(selectById(approval.getLaunchUserId()));
            approvalUsers.add(approvalUser);
        }
        return approvalUsers;
    }

    //通过id找对象
    public  User selectById(String userId){
        User user = userMapper.selectById(userId);

        return user;
    }
}
